﻿using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Devonline.AspNetCore;

/// <summary>
/// 数据处理事务上下文
/// </summary>
public class DataProtectionDbContext(DbContextOptions<DataProtectionDbContext> options) : DbContext(options), IDataProtectionKeyContext
{
    /// <summary>
    /// 数据保护密钥
    /// </summary>
    public virtual DbSet<DataProtectionKey> DataProtectionKeys { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);

        modelBuilder.Entity<DataProtectionKey>(b =>
        {
            b.ToTable("data_protection_key");
            b.HasKey(x => x.Id);
            b.Property(x => x.Id).HasColumnName("id").IsRequired();
            b.Property(x => x.FriendlyName).HasColumnName("friendly_name").IsRequired().HasMaxLength(128);
            b.Property(x => x.Xml).HasColumnName("xml").IsRequired().HasMaxLength(1024);
        });
    }
}